//
// File: upsconv1.cpp
//
// MATLAB Coder version            : 3.4
// C/C++ source code generated on  : 16-Nov-2021 20:58:22
//

// Include Files
#include "rt_nonfinite.h"
#include "xiaoboband.h"
#include "upsconv1.h"
#include "xiaoboband_emxutil.h"
#include "wkeep1.h"
#include "convn_kernel.h"

// Function Definitions

//
// Arguments    : const emxArray_real_T *x
//                double s
//                emxArray_real_T *y
// Return Type  : void
//
void upsconv1(const emxArray_real_T *x, double s, emxArray_real_T *y)
{
  int b_y;
  int cEnd1;
  emxArray_real_T *b_y1;
  int c_size_idx_0;
  double c_data[18];
  int iC;
  static const double B[10] = { 0.0033357252850015492, 0.012580751999015526,
    -0.0062414902130117052, -0.077571493840065148, -0.03224486958502952,
    0.24229488706619015, 0.13842814590110342, -0.72430852843857441,
    0.60382926979747287, -0.160102397974125 };

  int iB;
  int lastRowA;
  int aidx;
  int cidx;
  int r;
  if (x->size[0] == 0) {
    cEnd1 = y->size[0];
    y->size[0] = 1;
    emxEnsureCapacity_real_T1(y, cEnd1);
    y->data[0] = 0.0;
  } else {
    b_y = (x->size[0] << 1) - 2;
    cEnd1 = y->size[0];
    y->size[0] = b_y + 1;
    emxEnsureCapacity_real_T1(y, cEnd1);
    for (cEnd1 = 0; cEnd1 <= b_y; cEnd1++) {
      y->data[cEnd1] = 0.0;
    }

    for (b_y = 1; b_y <= x->size[0]; b_y++) {
      y->data[(b_y << 1) - 2] = x->data[b_y - 1];
    }

    emxInit_real_T1(&b_y1, 1);
    if (10 > y->size[0]) {
      c_size_idx_0 = y->size[0] + 9;
      b_y = y->size[0];
      if (0 <= b_y + 8) {
        memset(&c_data[0], 0, (unsigned int)((b_y + 9) * (int)sizeof(double)));
      }

      cEnd1 = y->size[0] + 8;
      iC = 0;
      iB = 0;
      for (b_y = 0; b_y < y->size[0]; b_y++) {
        if (b_y + 10 <= cEnd1) {
          lastRowA = 10;
        } else {
          lastRowA = (cEnd1 - b_y) + 1;
        }

        aidx = 0;
        cidx = iC;
        for (r = 1; r <= lastRowA; r++) {
          c_data[cidx] += y->data[iB] * B[aidx];
          aidx++;
          cidx++;
        }

        iB++;
        iC++;
      }

      cEnd1 = b_y1->size[0];
      b_y1->size[0] = c_size_idx_0;
      emxEnsureCapacity_real_T1(b_y1, cEnd1);
      for (cEnd1 = 0; cEnd1 < c_size_idx_0; cEnd1++) {
        b_y1->data[cEnd1] = c_data[cEnd1];
      }
    } else {
      cEnd1 = b_y1->size[0];
      b_y1->size[0] = y->size[0] + 9;
      emxEnsureCapacity_real_T1(b_y1, cEnd1);
      b_y = y->size[0];
      for (cEnd1 = 0; cEnd1 <= b_y + 8; cEnd1++) {
        b_y1->data[cEnd1] = 0.0;
      }

      eml_conv2(b_y1, y, B, 0, y->size[0] + 8);
    }

    wkeep1(b_y1, (int)s, y);
    emxFree_real_T(&b_y1);
  }
}

//
// File trailer for upsconv1.cpp
//
// [EOF]
//
